﻿using System;
using UnityEngine;
using UnityEngine.Serialization;

// Token: 0x02000049 RID: 73
[ExecuteInEditMode]
[RequireComponent(typeof(Light))]
[AddComponentMenu("Alloy/Area Light")]
public class AlloyAreaLight : MonoBehaviour
{
	// Token: 0x1700002E RID: 46
	// (get) Token: 0x0600027F RID: 639 RVA: 0x0000C63C File Offset: 0x0000A83C
	private Light Light
	{
		get
		{
			if (this.m_light == null)
			{
				this.m_light = base.GetComponent<Light>();
			}
			return this.m_light;
		}
	}

	// Token: 0x1700002F RID: 47
	// (get) Token: 0x06000280 RID: 640 RVA: 0x0000C664 File Offset: 0x0000A864
	// (set) Token: 0x06000281 RID: 641 RVA: 0x0000C66C File Offset: 0x0000A86C
	public float Radius
	{
		get
		{
			return this.m_radius;
		}
		set
		{
			if (this.m_radius != value)
			{
				this.m_radius = value;
				this.UpdateBinding();
			}
		}
	}

	// Token: 0x17000030 RID: 48
	// (get) Token: 0x06000282 RID: 642 RVA: 0x0000C688 File Offset: 0x0000A888
	// (set) Token: 0x06000283 RID: 643 RVA: 0x0000C690 File Offset: 0x0000A890
	public float Length
	{
		get
		{
			return this.m_length;
		}
		set
		{
			if (this.m_length != value)
			{
				this.m_length = value;
				this.UpdateBinding();
			}
		}
	}

	// Token: 0x17000031 RID: 49
	// (get) Token: 0x06000284 RID: 644 RVA: 0x0000C6AC File Offset: 0x0000A8AC
	// (set) Token: 0x06000285 RID: 645 RVA: 0x0000C6B4 File Offset: 0x0000A8B4
	public float Intensity
	{
		get
		{
			return this.m_intensity;
		}
		set
		{
			if (this.m_intensity != value)
			{
				this.m_intensity = value;
				this.UpdateBinding();
			}
		}
	}

	// Token: 0x17000032 RID: 50
	// (get) Token: 0x06000286 RID: 646 RVA: 0x0000C6D0 File Offset: 0x0000A8D0
	// (set) Token: 0x06000287 RID: 647 RVA: 0x0000C6D8 File Offset: 0x0000A8D8
	public Color Color
	{
		get
		{
			return this.m_color;
		}
		set
		{
			if (this.m_color != value)
			{
				this.m_color = value;
				this.UpdateBinding();
			}
		}
	}

	// Token: 0x17000033 RID: 51
	// (get) Token: 0x06000288 RID: 648 RVA: 0x0000C6F8 File Offset: 0x0000A8F8
	// (set) Token: 0x06000289 RID: 649 RVA: 0x0000C700 File Offset: 0x0000A900
	public bool HasSpecularHighlight
	{
		get
		{
			return this.m_hasSpecularHightlight;
		}
		set
		{
			if (this.m_hasSpecularHightlight != value)
			{
				this.m_hasSpecularHightlight = value;
				this.UpdateBinding();
			}
		}
	}

	// Token: 0x17000034 RID: 52
	// (get) Token: 0x0600028A RID: 650 RVA: 0x0000C71C File Offset: 0x0000A91C
	// (set) Token: 0x0600028B RID: 651 RVA: 0x0000C724 File Offset: 0x0000A924
	public bool IsAnimatedByClip
	{
		get
		{
			return this.m_isAnimatedByClip;
		}
		set
		{
			this.m_isAnimatedByClip = value;
		}
	}

	// Token: 0x0600028C RID: 652 RVA: 0x0000C730 File Offset: 0x0000A930
	public void UpdateBinding()
	{
		Light light = this.Light;
		float range = light.range;
		float num = range * 2f;
		this.m_length = Mathf.Clamp(this.m_length, 0f, num);
		this.m_intensity = Mathf.Max(this.m_intensity, 0f);
		Color color = light.color;
		color.r = this.m_color.r;
		color.g = this.m_color.g;
		color.b = this.m_color.b;
		color *= this.m_intensity;
		if (light.type == LightType.Directional)
		{
			this.m_radius = Mathf.Clamp(this.m_radius, 0f, 1f);
			color.a = this.m_radius * 10f;
		}
		else
		{
			this.m_radius = Mathf.Clamp(this.m_radius, 0f, range);
			float a = this.m_radius / range;
			float num2 = this.m_length / num;
			color.a = Mathf.Ceil(num2 * 1000f) + Mathf.Min(a, 0.999f);
		}
		color.a = Mathf.Max(1E-05f, color.a);
		color.a *= ((!this.m_hasSpecularHightlight) ? -1f : 1f);
		light.color = color;
		light.intensity = 1f;
		this.m_lastRange = range;
	}

	// Token: 0x0600028D RID: 653 RVA: 0x0000C8B0 File Offset: 0x0000AAB0
	private void Reset()
	{
		Light component = base.GetComponent<Light>();
		if (component != null)
		{
			this.m_intensity = Mathf.LinearToGammaSpace(component.intensity);
			this.m_color.r = component.color.r;
			this.m_color.g = component.color.g;
			this.m_color.b = component.color.b;
		}
		else
		{
			this.m_color.r = 1f;
			this.m_color.g = 1f;
			this.m_color.b = 1f;
			this.m_intensity = 1f;
		}
		this.m_hasSpecularHightlight = true;
		this.m_color.a = 1E-05f;
		this.m_radius = 0f;
		this.UpdateBinding();
	}

	// Token: 0x0600028E RID: 654 RVA: 0x0000C994 File Offset: 0x0000AB94
	private void Update()
	{
		if (this.m_isAnimatedByClip || this.Light.range != this.m_lastRange)
		{
			this.UpdateBinding();
		}
	}

	// Token: 0x040001B8 RID: 440
	private const float c_minimumLightSize = 1E-05f;

	// Token: 0x040001B9 RID: 441
	[SerializeField]
	private Color m_color = new Color(1f, 1f, 1f, 0f);

	// Token: 0x040001BA RID: 442
	[SerializeField]
	private float m_intensity = 1f;

	// Token: 0x040001BB RID: 443
	[SerializeField]
	[FormerlySerializedAs("m_size")]
	private float m_radius;

	// Token: 0x040001BC RID: 444
	[SerializeField]
	private float m_length;

	// Token: 0x040001BD RID: 445
	[SerializeField]
	private bool m_hasSpecularHightlight = true;

	// Token: 0x040001BE RID: 446
	[SerializeField]
	private bool m_isAnimatedByClip;

	// Token: 0x040001BF RID: 447
	private Light m_light;

	// Token: 0x040001C0 RID: 448
	private float m_lastRange;

	// Token: 0x040001C1 RID: 449
	[HideInInspector]
	public Texture2D DefaultSpotLightCookie;
}
